package com.dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.model.Origin;
import com.util.DataUtil;

public class OriginDAO {

	public ArrayList<Origin> select() {
		ArrayList<Origin> list = new ArrayList<Origin>();
		
		Connection conn = DataUtil.getConnection();
		try {
			CallableStatement stmt = conn.prepareCall("{ Call usp_dms_OriginSelect }");
			//stmt.setInt("@Origin_Id", 0);
			ResultSet rs = DataUtil.executeStore(stmt);
			
			// Gets entities from resultset
			while (rs.next()) {
				Origin entity = new Origin(rs.getInt("Origin_Id"), 
										rs.getString("OriginName"));
				list.add(entity);// add to list
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			DataUtil.disconnected();
		}
		return (list.isEmpty()) ? null : list;
	}

	public Origin select(int originId) {
		return null;
	}
}
